$(function() {
	$("#header").load('header.html', function() {
		loadHeader(2)
	});
	$("#footer").load('footer.html', function() {});
	$("#tab").load('tab.html', function() {});
	//获取url中的参数
	function getUrlParam(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
		var r = window.location.search.substr(1).match(reg); //匹配目标参数
		if(r != null) return unescape(r[2]);
		return null; //返回参数值
	}
	//接收URL中的参数
	var id = getUrlParam('HosID');
	$('.hos-detail-main').show();
	$('.case-main').hide();
	$('.onshop-main').hide();
	$('.doc-main').hide();
	$('.doc-pro-l').on('click', '#hosp-item-1', function() {
		$('.hos-detail-main').show();
		$('.case-main').hide();
		$('.onshop-main').hide();
		$('.doc-main').hide();
		$('.doc-pro-l li:eq(0)').addClass('active').siblings('.active').removeClass('active')
	})
	$('.doc-pro-l').on('click', '#hosp-item-3', function() {
		$('.doc-main').show();
		$('.case-main').hide();
		$('.hos-detail-main').hide();
		$('.onshop-main').hide();
		$('.doc-pro-l li:eq(1)').addClass('active').siblings('.active').removeClass('active')
	})
	$('.doc-pro-l').on('click', '#hosp-item-4', function() {
		$('.case-main').show();
		$('.onshop-main').hide();
		$('.doc-main').hide();
		$('.hos-detail-main').hide();
		$('.doc-pro-l li:eq(2)').addClass('active').siblings('.active').removeClass('active')
	})

	//console.log(id);
	$.ajax({
		url: host + '/MtmlAPI/HospitalDetails',
		type: 'POST',
		dataType: 'JSON',
		data: {
			cid: cid,
			HosID: id,
			lat: '32.07766',
			lng: '118.77158'
		},
		success: function(res) {
			if(res.state) {
				var obj = res.data
				var list=obj.Environment
				var str=obj.Tags.replace(/\|/g, "，")
				var bb=str.substr(0, str.length - 1); 
				console.log()
				if(str.length!==0){
					tagHtml =`<div class="hospital-pto">擅长项目: ${bb}</div>`
				}else{tagHtml=''}
				imgList=''
				$.each(list,function(i,item){
					imgList += `<div class="swiper-slide" style='background-image: url(${item.URL});'></div>`
				})
				html=''
				if(list.length!==0){$(html =`
						<div class="swiper-button-prev"></div>
						<div class="swiper-button-next"></div>
						<div class="swiper-wrapper">${imgList}</div>`)
				}else{html=''}
				
				$('.good-detail-r').prepend(
					`
                    <div class="good-detail-pro">
	                    <div class="hospital-img" style="background-image: url(${obj.HeadImage});"></div>
	                    <div class="good-detail-txt">
	                    <div class="good-detail-good">${obj.HosName}</div>
	                    <ul class="good-detail-pro-txt">
	                    	<li>电话: ${obj.HosPhone} </li>
	                        <li>所在地区: ${obj.Address}</li>
	                        <li>营业时间: ${obj.HosTime}</li>
	                    </ul>
	                     ${tagHtml}
	                	</div>
	                </div>
	                <div class="hospital-con">${obj.Introduction}</div>
                	<div class="swiper-container">${html}</div>
                `
				)
				
				var swiper = new Swiper({
					el: '.swiper-container',
					initialSlide: 2,
					spaceBetween: 50,
					slidesPerView: 2,
					centeredSlides: true,
					slideToClickedSlide: true,
					grabCursor: true,
					mousewheel: {
						enabled: true,
					},
					keyboard: {
						enabled: true,
					},
					navigation: {
						nextEl: '.swiper-button-next',
						prevEl: '.swiper-button-prev',
					},
				});

			} else {

			}
		},
		error: function() {}
	})
})